var netcore = require('../../../utils/network.js')
var tripleDes = require('../../../utils/CKCrypto.js')
var comm=require('../../../utils/comm_util.js')
const app = getApp()
function getIndexFreeCourse(gradeLevel,callBack){
  if (gradeLevel==null||gradeLevel==undefined){
    gradeLevel="1";
  }
  getCourse("1", gradeLevel, "0", null, null, 1, 5, callBack)
}
function getIndexRecomandCourse(gradeLevel,callBack){
  if (gradeLevel == null || gradeLevel == undefined) {
    gradeLevel = "1";
  }
  getCourse("2", gradeLevel, "0", null, null, 1, 5, callBack)
}
function getCourse(type, grade, entrytype, projectType, projectEdition,pageIndex,pageLimit,callBack){
  var params=new Map();
  params.set("type", type)
  params.set("grade", grade)
  params.set("entrytype", entrytype)
  params.set("latitude", app.globalData.userLocationInfo.lat)
  params.set("longitude", app.globalData.userLocationInfo.lng)
  if (projectType != null && (projectType + "").length > 0 && Number(projectType)>0){
    params.set("projectType", projectType)
  }
  if (projectEdition != null && (projectEdition + "").length > 0 && Number(projectEdition) > 0) {
    params.set("projectEdition", projectEdition)
  }
  params.set("currentPage", pageIndex)
  params.set("pageSize", pageLimit)
  netcore.requestPost("course/getCourseLists.do",params,function(success){
    success.forEach(function(item,index){
      if (item.showFullNameFlag == 0 && typeof (item.courseTeacherRealName) != undefined && item.courseTeacherRealName.length>0) {
        item.courseTeacherRealName = item.courseTeacherRealName.substring(0, 1) + "老师"
      }
      item.clickCount = comm.covertNumber(item.clickCount)
      item.buyCount = comm.covertNumber(item.buyCount)
      item.playCount = comm.covertNumber(item.playCount)
    })
    callBack(success)
  },function(code,errMsg){
    wx.showToast({
      title: errMsg,
      duration:3000
    })
  })
}
module.exports = {
  getIndexFreeCourse: getIndexFreeCourse,
  getIndexRecomandCourse: getIndexRecomandCourse,
  getCourse: getCourse
}